package hojadetrabajo4;

public class doublyLinkedList<E> extends abstractList<E>
{
    protected int count;
    protected doublyLinkedNode<E> head;
    protected doublyLinkedNode<E> tail;

    public doublyLinkedList()
    // post: constructs an empty list
    {
       head = null;
       tail = null;
       count = 0;
    }


    public void push(E value)
    // pre: value is not null
    // post: adds new value to tail of list
    {
        tail = new doublyLinkedNode<E>(value, null, tail);
        // fix up head
        if (head == null) head = tail;
        count++;
    }
    
    public E pop()
    // pre: list is not empty
    // post: removes value from tail of list
    {
    
        doublyLinkedNode<E> temp = tail;
        tail = tail.getPrevious();
        if (tail == null) {
            head = null;
        } else {
            tail.setNext(null);
        }
        count--;
        return temp.value();
    }
    
    @Override
     public E peek()
    {
       return tail.value();
    }
    public int size() {
        return count;
    }

    @Override
    public boolean isEmpty() {
        return size()==0;
    }

    @Override
    public void clear() {
        head=null;
        tail=null;
        count=0;
    }
}